// pages/majorRecom/majorRecom.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    num:null,
    dev:null,
    nameList:[],
    scoreList:[],
    majorList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let type = options.type;
    let score = options.score;
    let admissionBatch = options.admissionBatch;
    let unvId = options.unvId;
    this.setData({
      num:options.num,
      dev:options.dev,
    })
    console.log(options.num,options.dev);
    wx.request({
      url: 'http://192.168.43.204:9527/willing/universityInfo',
      data:{
        type:type,
        admissionBatch:admissionBatch,
        unvId:unvId,
      },
      success:(res)=>{
        console.log("###",res);
        this.setData({
          code:res.data.code,
          name:res.data.name,
          scoreList:res.data.list,
        })
      }
    });
    wx.request({
      url: 'http://192.168.43.204:9527/willing/recommendMajor',
      data:{
        type:type,
        score:score,
        admissionBatch:admissionBatch,
        unvId:unvId,
      },
      success:(res)=>{
        this.setData({
          majorList:res.data,
        });
        for(let index = 0; index <res.data.length;index++){
          let majorName = [];
          majorName = res.data[index].name.split("（");
          this.data.nameList.push({
            title:majorName[0],
            jieshi:"（" + majorName[1],
          })
          res.data[index] = {...res.data[index], title:this.data.nameList[index].title,jieshi:this.data.nameList[index].jieshi}; 
        };
        this.setData({
          majorList:res.data,
        })
        console.log(this.data.majorList);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})